/******************************************************************************
 * SVN­Versioning-Information:
 * ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
 * $LastChangedRevision: 6 $
 * $LastChangedBy: c.a.duevel $
 * $LastChangedDate: 2009-08-26 15:12:37 +0000 (Wed, 26 Aug 2009) $
 * $HeadURL: http://robofight.googlecode.com/svn/trunk/Server/src/de/hft_stuttgart/botwar/server/model/Shield.java $
 ******************************************************************************/
package de.hft_stuttgart.botwar.server.model;

import de.hft_stuttgart.botwar.common.models.ShieldInfo;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 *
 * @author pmv-mail@gmx.de, c.a.duevel@gmail.com
 */
@Entity
@Table(name = "tblShield")
public class Shield implements Serializable {

    @Id
    private String name;
    @Column(nullable = false)
    private int health;
    @Column(nullable = false)
    private int cost;
    @Column(nullable = false)
    private int weight;
    @Column(nullable = false)
    private int levelRank;
    @OneToMany
    private Collection<RobotConfiguration> robots;

    /**
     * This constructor just exists because of the requirements of jpa.
     * Please do not use.
     * @deprecated
     */
    public Shield() {
    }

    /**
     * Creates a new Shield.
     * @param name The name of this shield.
     * @param health The amount of firepower this shield can absorb.
     * @param weight The weight of that shield.
     * @param cost The cost of that shield
     * @param levelRank The level a player has to have to get this shield
     */
    public Shield(final String name,
            final int health,
            final int weight,
            final int cost,
            final int levelRank) {
        setName(name);
        setHealth(health);
        setCost(cost);
        setWeight(weight);
        setLevelRank(levelRank);
    }

    /**
     *
     * @return The name of this shield.
     */
    public String getName() {
        return name;
    }

    /**
     * @param name The name of this shield.
     **/
    public void setName(final String name) {
        if (name == null) {
            throw new IllegalArgumentException("Null value is not allowed.");
        }
        this.name = name;
    }

    /**
     * @return The amount of firepower this shield can absorb.
     */
    public int getHealth() {
        return health;
    }

    /**
     * @param health The amount of firepower this shield can absorb.
     */
    public void setHealth(final int health) {
        if (health < 0) {
            throw new IllegalArgumentException("No negative health allowed");
        }

        this.health = health;
    }

    /**
     * @return The cost of that shield
     */
    public int getCost() {
        return cost;
    }

    /**
     * @param cost The cost of that shield
     */
    public void setCost(final int cost) {
        if (cost < 0) {
            throw new IllegalArgumentException("No negative cost allowed");
        }
        this.cost = cost;
    }

    /**
     * @return The level a player has to have to get this shield
     */
    public int getLevelRank() {
        return levelRank;
    }

    /**
     * @param levelRank The level a player has to have to get this shield
     */
    public void setLevelRank(final int levelRank) {
        if (levelRank < 1) {
            throw new IllegalArgumentException(
                                    "Levelrank must be greater then zero!");
        }
        this.levelRank = levelRank;
    }
    /**
     *
     * @return The weight of this shield
     */
    public int getWeight() {
        return weight;
    }
   /**
     *
     * @param weight The weight of this shield.
     */
    public void setWeight(final int weight) {
        if (weight < 0) {
            throw new IllegalArgumentException("No negative Weight allowed");
        }
        this.weight = weight;
    }
/**
 *
 * @return Alle the robot configurations using this shield
 */
    public Collection<RobotConfiguration> getRobots() {
        return robots;
    }
/**
 *
 * @return ShieldInfo containing all the information of the shield.
 */
    public ShieldInfo getInfo() {
        return new ShieldInfo(levelRank, cost, health, weight, name);
    }
}
